
 //
 //  UIViewExtension.swift
 //  U17
 //
 //  Created by charles on 2017/11/13.
 //  Copyright © 2017年 None. All rights reserved.
 //
 
 import UIKit
 
extension Date {
    
    /// 获取当前 秒级 时间戳 - 10位
    var timeStamp : String {
        let timeInterval: TimeInterval = self.timeIntervalSince1970
        let timeStamp = Int(timeInterval)
        return "\(timeStamp)"
    }
    
    /// 获取当前 毫秒级 时间戳 - 13位
    var milliStamp : String {
        let timeInterval: TimeInterval = self.timeIntervalSince1970
        let millisecond = CLongLong(round(timeInterval*1000))
        return "\(millisecond)"
    }
    //MARK: -时间转时间戳函数
    func timeToTimeStamp(time: String ,inputFormatter:String) -> Double {
        let dfmatter = DateFormatter()
        //设定时间格式,这里可以设置成自己需要的格式
        dfmatter.dateFormat = inputFormatter
        let last = dfmatter.date(from: time)
        let timeStamp = last?.timeIntervalSince1970
        return timeStamp!
    }
    func timeDiff(start:Double,end:Double) -> String {
        let comicDate = end - start
        var tagString = ""
        if comicDate < 60 {
            tagString = "刚刚"
        } else if comicDate < 3600 {
            tagString = "\(Int(comicDate / 60))分钟前"
        } else if comicDate < 86400 {
            tagString = "\(Int(comicDate / 3600))小时前"
        } else if comicDate < 31536000{
            tagString = "\(Int(comicDate / 86400))天前"
        } else {
            tagString = "\(Int(comicDate / 31536000))年前"
        }
        return tagString
    }
}
